package com.ming.mallchat.common.user.service.adpater;

import com.ming.mallchat.common.user.domain.enums.ApplyReadStatusEnum;
import com.ming.mallchat.common.user.domain.enums.ApplyStatusEnum;
import com.ming.mallchat.common.user.domain.enums.ApplyTypeEnum;
import com.ming.mallchat.common.user.domain.vo.req.friend.FriendApplyReq;
import com.ming.mallchat.common.user.domain.vo.resp.friend.FriendApplyResp;
import com.ming.mallchat.common.user.domain.vo.resp.friend.FriendCheckResp;
import com.ming.mallchat.common.user.pojo.UserApply;
import lombok.Builder;
import lombok.Data;

import java.util.List;
import java.util.stream.Collectors;

/**
 * @author 86150
 * @date 2023/10/11
 */
public class FriendAdapter {

    public static UserApply buildFriendApply(Long uid, FriendApplyReq request) {
        return UserApply.builder()
                .uid(uid)
                .targetId(request.getTargetUid())
                .msg(request.getMsg())
                .status(ApplyStatusEnum.WAIT_APPROVAL.getCode())
                .readStatus(ApplyReadStatusEnum.UNREAD.getCode())
                .type(ApplyTypeEnum.ADD_FRIEND.getCode())
                .build();
    }

    public static List<FriendApplyResp> buildFriendApplyList(List<UserApply> records) {
        return records.stream().map(userApply -> {
            FriendApplyResp applyResp = new FriendApplyResp();
            applyResp.setUid(userApply.getUid());
            applyResp.setType(userApply.getType());
            applyResp.setApplyId(userApply.getId());
            applyResp.setMsg(userApply.getMsg());
            applyResp.setStatus(userApply.getStatus());
            return applyResp;
        }).collect(Collectors.toList());
    }
}
